<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

	<ui:composition 
	  xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      template="/view/templates/templateLayout.xhtml">
      
      <ui:define name="conteudo">      	
  	  <link rel="stylesheet" type="text/css" href="./estilos.css"/>
  	  
<h:form id="formManterVenda" prependId="false">  
	<p:panel id="panelManterVenda" header="Manter Venda" style="margin-bottom:20px; ">  
	<f:facet name="header">
		<h:outputText value="Manter Venda" styleClass="outputTextTitulo"/>
	</f:facet>
 	<p:growl id="growl" /> 
    	<h:panelGrid id="pgVenda" columns="2" style="margin-top:20px; margin-right:10%;">  
            <h:outputLabel value="Código" styleClass="outputLabel"/>  
            <h:outputLabel value="Data*" styleClass="outputLabel"/>             
            <p:inputText value="#{vendaBean.venda .idVenda}" styleClass="inputId" disabled="true"/>  
  			<p:inputText value="#{vendaBean.venda .dtVenda}"  styleClass="inputData" >
  				<f:convertDateTime dateStyle="medium"/>
  			</p:inputText>  
        </h:panelGrid> 
        <h:panelGrid id="pgAluno" columns="3" style="margin-right:10%;">  
            <h:outputLabel value="Código" styleClass="outputLabel"/>  
            <h:outputLabel value="Nome*" styleClass="outputLabel"/>     
            <h:outputLabel  />           
            <p:inputText value="#{vendaBean.venda .aluno.idAluno}" styleClass="inputId" />  
  			<p:inputText value="#{vendaBean.venda .aluno.nome}"  styleClass="inputDescricao" />  
  			<p:commandButton icon="ui-icon-search" actionListener="#{vendaBean.openDialogConsultarAluno}" immediate="true"/>
        </h:panelGrid>   
 
        
        <h:panelGrid id="pgItemVenda" columns="5" style="margin-right:10%;">  
            <h:outputLabel value="Código" styleClass="outputLabel"/>  
            <h:outputLabel value="Produto*" styleClass="outputLabel"/>  
            <h:outputLabel  />
            <h:outputLabel  value="Quantidade*" styleClass="outputLabel"/>
            <h:outputLabel  />
            <p:inputMask  value="#{vendaBean.itemVenda.produto.idProduto}" styleClass="inputId" />  
  			<p:inputText value="#{vendaBean.itemVenda.produto.descricao}" styleClass="inputDescricao" />
  			<p:commandButton  icon="ui-icon-search" actionListener="#{vendaBean.openDialogConsultarProduto}" immediate="true" />  			  
  			<p:inputMask  value="#{vendaBean.itemVenda.quantidade}" styleClass="inputId"/>  
  			<p:commandButton icon="ui-icon-circle-plus" action="#{vendaBean.addItemVenda}" update="growl"/>
        </h:panelGrid> 
        
        <p:dataTable  id="tableItemVenda" value="#{vendaBean.arrayItemVenda}" var="itemVenda" style="margin-top:30px; width:60%"  
        				rowKey="#{itemVenda.idItemVenda}" selection="#{vendaBean.itemVendaSelect}" >
			<p:column>
				<f:facet name="header">
					<h:outputText value="Código" />
				</f:facet>
				<h:outputText value="#{itemVenda.produto.idProduto}" />
			</p:column>
			<p:column>
				<f:facet name="header">
					<h:outputText value="Produto" />
				</f:facet>
				<h:outputText value="#{itemVenda.produto.descricao}" />
			</p:column>
			<p:column>
				<f:facet name="header">
					<h:outputText value="Quantidade" />
				</f:facet>
				<h:outputText value="#{itemVenda.quantidade}" />
			</p:column>
			<p:column>
				<f:facet name="header">
					<h:outputText value="Preço Unitário" />
				</f:facet>
				<h:outputText value="#{itemVenda.produto.valor}" />
			</p:column>
			<p:column>
				<f:facet name="header">
					<h:outputText value="Preço Total" />
				</f:facet>
				<h:outputText value="#{itemVenda.precoTotal}" />
			</p:column>

       	 	<p:column style="width:4%">  
        		<f:facet name="header">
        	 		<h:outputText value="Excluir" />
        		</f:facet>
         		<p:commandButton icon="ui-icon-pencil" title="Remover"  immediate="true">
         		</p:commandButton>
       	 	</p:column > 	
       	 	<f:facet name="footer" >
       	 		<h:outputText value="Total = R$ #{vendaBean.somaValorTotal}" >
       	 			
       	 		</h:outputText>
       	 	</f:facet>        
        </p:dataTable>

        	<h:panelGrid id="pgCondicaoPagamento" columns="5" style="margin-right:10%;">  
           	 	<h:outputLabel value="Código" styleClass="outputLabel"/>  
            	<h:outputLabel value="Condição de Pagamento*" styleClass="outputLabel"/>      
            	<h:outputLabel  />       
            	<h:outputLabel value="Código" styleClass="outputLabel"/>  
            	<h:outputLabel value="Forma de Pagamento*" styleClass="outputLabel"/>    
            	<p:inputText value="#{vendaBean.venda .condicaoPagamento.idCondicaoPagamento}" styleClass="inputId" disabled="true"/>  
  				<p:inputText value="#{vendaBean.venda .condicaoPagamento.descricao}"  styleClass="inputDescricao" style="width:150px;" immediate="true" disabled="true"/>  
  				<p:commandButton icon="ui-icon-search" actionListener="#{vendaBean.openDialogConsultarCondicaoPagamento}" immediate="true" disabled="#{vendaBean.disableCondicao()}"/>  
            	<p:inputText value="#{vendaBean.venda .condicaoPagamento.formaPagamento.idFormaPagamento}" styleClass="inputId" disabled="true"/>  
  				<p:inputText value="#{vendaBean.venda .condicaoPagamento.formaPagamento.descricao}"  styleClass="inputDescricao" style="width:150px;" disabled="true"/>  
        	</h:panelGrid> 
        	<h:panelGrid id="pgTotal" columns="3" style="margin-right:10%;">  
            	<h:outputLabel value="Desconto(%)" styleClass="outputLabel"/>  
            	<h:outputLabel  />
            	<h:outputLabel value="Total da Venda(R$)" styleClass="outputLabel"/> 
            	
            	<p:inputText value="#{vendaBean.venda .desconto}" styleClass="inputId" style="width:70px"/>  
            	<p:commandButton icon="ui-icon-calculator" action="#{vendaBean.calculaTotalVenda}" process="@this pgTotal" disabled="#{vendaBean.disableCalculaTotalVenda()}" style="text-align:left; float:left"/>
  				<p:inputText value="#{vendaBean.venda .valorTotal}"  styleClass="inputData" disabled="true"  />  
        	</h:panelGrid> 

        	<p:dataTable  id="tableParcela" value="#{vendaBean.listContaReceber}" var="cr" style="margin-top:30px; width:20%">        				
				<p:column>
					<f:facet name="header">
						<h:outputText value="Data de Vencimento" />
					</f:facet>
					<h:outputText value="#{cr.dtVencimento}" >
						<f:convertDateTime dateStyle="medium"/>
					</h:outputText>
				</p:column>
				<p:column>
					<f:facet name="header">
						<h:outputText value="Valor" />
					</f:facet>
					<h:outputText value="R$ #{cr.valor}" />
				</p:column>      
    	    </p:dataTable>
    </p:panel>  
    <p:commandButton value="Salvar" actionListener="#{vendaBean.saveVenda}" update="panelManterVenda" style="margin-right:20px; margin-left:10px;" /> 
	<p:commandButton value="Cancelar" style="margin-right:20px;" /> 
</h:form>  	
<ui:include src="/view/venda/dialogConsultarAluno.xhtml"></ui:include>
<ui:include src="/view/venda/dialogConsultarProduto.xhtml"></ui:include>
<ui:include src="/view/venda/dialogConsultarCondicaoPagamento.xhtml"></ui:include>


</ui:define>
</ui:composition>
